export function Post(url,data,isJson) {
    // body...
    var json = null;
    var httpRequest = new XMLHttpRequest();
    httpRequest.open('POST', url, false); //第二步：打开连接
    try {
        httpRequest.setRequestHeader('Authorization',sessionStorage.token.replace("\"","").replace("\"",""));
    }catch (e) {
        console.log(e);
        return json
    }
    
    
    if (isJson) {
        httpRequest.setRequestHeader("Content-type","application/json");
        data = JSON.stringify(data)
    }else{
        var ret = '';
        httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        for (let it in datas) {
            ret += encodeURIComponent(it) + '=' + encodeURIComponent(datas[it]) + '&';
        }
        data = ret;
    }
    //设置请求头 注：post方式必须设置请求头（在建立连接后设置请求头）
    httpRequest.send(data);//发送请求 将情头体写在send中

    /**
     * 获取数据后的处理程序
     */
    
    if (httpRequest.readyState == 4 && httpRequest.status == 200) {//验证请求是否发送成功
        json = httpRequest.responseText;//获取到服务端返回的数据
    }
    // httpRequest.onreadystatechange = function () {//请求后的回调接口，可将请求成功后要执行的程序写在其中
    //     if (httpRequest.readyState == 4 && httpRequest.status == 200) {//验证请求是否发送成功
    //         json = httpRequest.responseText;//获取到服务端返回的数据
    //         console.log("1",json);
    //     }
    // };
    return json
}